<?php

/*
 
    MMetaverse - Open Metaverse Access Library

    Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

    http://www.maryjanesoft.com
    http://www.marlonj.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General
    Public License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA  02111-1307  USA

    $Id$

*/

/**
 * @package mjs.mmetaverse.manager
 */

/**
 * Information of a metaverse user
 */
class MUser {
    /**
     * The user identifier
     *
     * @var MUUID
     */
    private $uuid;

    /**
     * First name
     *
     * @var string
     */
    private $firstName;

    /**
     * Last name
     *
     * @var string
     */
    private $lastName;

    /**
     * Password Hash
     *
     * @var string
     */
    private $passwordHash;

    /**
     * Password Salt
     *
     * @var string
     */
    private $passwordSalt;

    /**
     * Home Region X
     *
     * @var integer
     */
    private $homeRegionX;

    /**
     * Home Region Y
     *
     * @var integer
     */
    private $homeRegionY;

    /**
     * Home Location X
     *
     * @var float
     */
    private $homeLocationX;

    /**
     * Home Location Y
     *
     * @var float
     */
    private $homeLocationY;

    /**
     * Home Location Z
     *
     * @var float
     */
    private $homeLocationZ;

    /**
     * Home Look At X
     *
     * @var float
     */
    private $homeLookAtX;

    /**
     * Home Look At Y
     *
     * @var float
     */
    private $homeLookAtY;

    /**
     * Home Look At Z
     *
     * @var float
     */
    private $homeLookAtZ;

    /**
     * Created
     *
     * @var integer
     */
    private $created;

    /**
     * Last Login
     *
     * @var integer
     */
    private $lastLogin;

    /**
     * Root inventory folder id
     *
     * @var MUUID
     */
    private $rootInventoryFolderID;

    /**
     * User Inventory URI
     *
     * @var string
     */
    private $userInventoryURI;

    /**
     * User Asset URI
     *
     * @var string
     */
    private $userAssetURI;

    /**
     * Profile Can Do Mask
     *
     * @var integer
     */
    private $profileCanDoMask;

    /**
     * Profile Want Do Mask
     *
     * @var integer
     */
    private $profileWantDoMask;

    /**
     * Profile About Text
     *
     * @var string
     */
    private $profileAboutText;

    /**
     * Profile First Text
     *
     * @var string
     */
    private $profileFirstText;

    /**
     * Profile Image
     *
     * @var MUUID
     */
    private $profileImage;

    /**
     * Profile First Image
     *
     * @var MUUID
     */
    private $profileFirstImage;

    /**
     * Web Login key
     *
     * @var MUUID
     */
    private $webLoginKey;

    /**
     * Home Region ID
     *
     * @var MUUID
     */
    private $homeRegionID;

    /**
     * User Flags
     *
     * @var integer
     */
    private $userFlags;

    /**
     * God Level
     *
     * @var integer
     */
    private $godLevel;

    /**
     * Custom Type
     *
     * @var string
     */
    private $customType;

    /**
     * Partner
     *
     * @var MUUID
     */
    private $partner;

    /**
     * Email
     *
     * @var String
     */
    private $email;

    /**
     * Create a metaverse user 
     *
     * @param MUIID $uuid
     * @param string $firstName
     * @param string $lastName
     * @param string $email
     * @param string $passwordHash
     * @param string $passwordSalt
     * @param integer $homeRegionX
     * @param integer $homeRegionY
     * @param float $homeLocationX
     * @param float $homeLocationY
     * @param float $homeLocationZ
     * @param float $homeLookAtX
     * @param float $homeLookAtY
     * @param float $homeLookAtZ
     * @param integer $created
     * @param integer $lastLogin
     * @param string $userInventoryURI
     * @param string $userAssetURI
     * @param integer $profileCanDoMask
     * @param integer $profileWantDoMask
     * @param string $profileAboutText
     * @param string $profileFirstText
     * @param integer $userFlags
     * @param integer $godLevel
     * @param string $customType
     */
    public function MUser(MUUID $uuid, $firstName, $lastName, $email = '',
        $passwordHash = '', $passwordSalt = '',
        $homeRegionX = 0, $homeRegionY = 0,
        $homeLocationX = 0, $homeLocationY = 0, $homeLocationZ = 0,
        $homeLookAtX = 0.0, $homeLookAtY = 0.0, $homeLookAtZ = 0.0,
        $created = 0, $lastLogin = 0,
        $userInventoryURI = '', $userAssetURI = '',
        $profileCanDoMask = 0, $profileWantDoMask = 0,
        $profileAboutText = '', $profileFirstText = '',
        $userFlags = 0, $godLevel = 0, $customType = '') {

        // Set attributes 
        $this->uuid = $uuid;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->email = $email;
        $this->passwordHash = $passwordHash;
        $this->passwordSalt = $passwordSalt;
        $this->homeRegionX = $homeRegionX;
        $this->homeRegionY = $homeRegionY;
        $this->homeLocationX = $homeLocationX;
        $this->homeLocationY = $homeLocationY;
        $this->homeLocationZ = $homeLocationZ;
        $this->homeLookAtX = $homeLookAtX;
        $this->homeLookAtY = $homeLookAtY;
        $this->homeLookAtZ = $homeLookAtZ;
        $this->created = $created;
        $this->lastLogin = $lastLogin;
        $this->userInventoryURI = $userInventoryURI;
        $this->userAssetURI = $userAssetURI;
        $this->profileWantDoMask = $profileWantDoMask;
        $this->profileCanDoMask = $profileCanDoMask;
        $this->profileAboutText = $profileAboutText;
        $this->profileFirstText = $profileFirstText;
        $this->userFlags = $userFlags;
        $this->godLevel = $godLevel;
        $this->customType = $customType;

        // Init uuids
        $this->profileImage = new MUUID();
        $this->profileFirstImage = new MUUID();
        $this->rootInventoryFolderID = new MUUID();
        $this->webLoginKey = new MUUID();
        $this->homeRegionID = new MUUID();
        $this->partner = new MUUID();
    }

    /**
     * Return the user identifier
     *
     * @return MUUID The user identifier
     */
    public function getUUID() {
        return $this->uuid;
    }

    /**
     * Return the first name
     *
     * @return string first name
     */
    public function getFirstName() {
        return $this->firstName;
    }

    /**
     * Return the last name
     *
     * @return string last name
     */
    public function getLastName() {
        return $this->lastName;
    }

    /**
     * Return the password hash 
     *
     * @return string password hash 
     */
    public function getPasswordHash() {
        return $this->passwordHash;
    }

    /**
     * Return the password salt
     *
     * @return string password salt
     */
    public function getPasswordSalt() {
        return $this->passwordSalt;
    }

    /**
     * Return home region x
     *
     * @return integer region x
     */
    public function getHomeRegionX() {
        return $this->homeRegionX;
    }

    /**
     * Return home region y
     *
     * @return integer region y
     */
    public function getHomeRegionY() {
        return $this->homeRegionY;
    }

    /**
     * Return home location x
     *
     * @return float location x
     */
    public function getHomeLocationX() {
        return $this->homeLocationX;
    }
    
    /**
     * Return home location y
     *
     * @return float location y
     */
    public function getHomeLocationY() {
        return $this->homeLocationY;
    }

    /**
     * Return home location z
     *
     * @return float location z
     */
    public function getHomeLocationZ() {
        return $this->homeLocationY;
    }

    /**
     * Return home look at x
     *
     * @return float
     */
    public function getHomeLookAtX() {
        return $this->homeLookAtX;
    }

    /**
     * Return home look at x
     *
     * @return float
     */
    public function getHomeLookAtY() {
        return $this->homeLookAtY;
    }

    /**
     * Return home look at z
     *
     * @return float
     */
    public function getHomeLookAtZ() {
        return $this->homeLookAtZ;
    }

    /**
     * Return the crated time
     *
     * @return integer
     */
    public function getCreated() {
        return $this->created;
    }

    /**
     * Return the last login
     *
     * @return integer
     */
    public function getLastLogin() {
        return $this->lastLogin;
    }

    /**
     * Return the rootInventoryFolderID
     *
     * @return MUUID
     */
    public function getRootInventoryFolderID() {
        return $this->rootInventoryFolderID;
    }

    /**
     * Return the user inventory URI
     *
     * @return string
     */
    public function getUserInventoryURI() {
        return $this->userInventoryURI;
    }

    /**
     * Return the asset URI
     *
     * @return string
     */
    public function getUserAssetURI() {
        return $this->userAssetURI;
    }

    /**
     * Return profile can do mask
     *
     * @return integer
     */
    public function getProfileCanDoMask() {
        return $this->profileCanDoMask;
    }

    /**
     * Return profile want do mask
     *
     * @return integer
     */
    public function getProfileWantDoMask() {
        return $this->profileWantDoMask;
    }

    /**
     * Return the profile about text
     *
     * @return string
     */
    public function getProfileAboutText() {
        return $this->profileAboutText;
    }

    /**
     * Return the profile first text
     *
     * @return string
     */
    public function getProfileFirstText() {
        return $this->profileFirstText;
    }

    /**
     * Return the profile image uuid
     *
     * @return MUUID profile image uuid
     */
    public function getProfileImage() {
        return $this->profileImage;
    }

    /**
     * Return the profile image uuid
     *
     * @return MUUID profile image uuid
     */
    public function getProfileFirstImage() {
        return $this->profileFirstImage;
    }

    /**
     * Return
     *
     * @return MUUID uuid
     */
    public function getWebLoginKey() {
        return $this->webLoginKey;
    }

    /**
     * Return
     *
     * @return MUUID uuid
     */
    public function getHomeRegionID() {
        return $this->homeRegionID;
    }

    /**
     * Return
     *
     * @return integer
     */
    public function getUserFlags() {
        return $this->userFlags;
    }

    /**
     * Return
     *
     * @return integer
     */
    public function getGodLevel() {
        return $this->godLevel;
    }

    /**
     * Return
     *
     * @return string
     */
    public function getCustomType() {
        return $this->customType;
    }

    /**
     * Return
     *
     * @return MUUID uuid
     */
    public function getPartner() {
        return $this->partner;
    }

    /**
     * Return
     *
     * @return string
     */
    public function getEmail() {
        return $this->email;
    }

    /**
     * Update the profile image
     *
     * @param MUUID image uuid
     */
    public function setProfileImage(MUUID $profileImage) {
        $this->profileImage = $profileImage;
    }

    /**
     * Update the profile first image
     *
     * @param MUUID image uuid
     */
    public function setProfileFirstImage(MUUID $profileFirstImage) {
        $this->profileFirstImage = $profileFirstImage;
    }

    /**
     * Update the root inventory folder
     *
     * @param MUUID folder uuid
     */
    public function setRootInventoryFolderID(MUUID $rootInventoryFolderID) {
        $this->rootInventoryFolderID = $rootInventoryFolderID;
    }

    /**
     * Update web login key
     *
     * @param MUUID key uuid
     */
    public function setWebLoginKey(MUUID $webLoginKey) {
        $this->webLoginKey = $webLoginKey;
    }

    /**
     * Update Home Region
     *
     * @param MUUID region uuid
     */
    public function setHomeRegionID(MUUID $homeRegionID) {
        $this->homeRegionID = $homeRegionID;
    }

    /**
     * Update Patner
     *
     * @param MUUID user uuid
     */
    public function setPartner(MUUID $partner) {
        $this->partner = $partner;
    }

    /**
     * Set user password
     *
     * @param string plain password
     */
    public function setPassword($password) {
        $this->passwordHash = md5(md5($password).':');
    }
    
    /**
     * Return the string representation of the user
     *
     * @return string string representation of the user
     */
    public function __toString() {
        return $this->firstName . ' ' . $this->lastName;
    }
}
?>